package com.ruoyi.patent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patent.domain.PContractType;
import com.ruoyi.patent.service.IPContractTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同类型Controller
 *
 * @author jwinni
 * @date 2022-04-11
 */
@RestController
@RequestMapping("/contract/contractType")
public class PContractTypeController extends BaseController
{
    @Autowired
    private IPContractTypeService pContractTypeService;

    /**
     * 查询合同类型列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:list')")
    @GetMapping("/list")
    public TableDataInfo list(PContractType pContractType)
    {
        startPage();
        List<PContractType> list = pContractTypeService.selectPContractTypeList(pContractType);
        return getDataTable(list);
    }

    /**
     * 导出合同类型列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:export')")
    @Log(title = "合同类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PContractType pContractType)
    {
        List<PContractType> list = pContractTypeService.selectPContractTypeList(pContractType);
        ExcelUtil<PContractType> util = new ExcelUtil<PContractType>(PContractType.class);
        util.exportExcel(response, list, "合同类型数据");
    }

    /**
     * 获取合同类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:query')")
    @GetMapping(value = "/{ctypeId}")
    public AjaxResult getInfo(@PathVariable("ctypeId") Long ctypeId)
    {
        return AjaxResult.success(pContractTypeService.selectPContractTypeByCtypeId(ctypeId));
    }

    /**
     * 新增合同类型
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:add')")
    @Log(title = "合同类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PContractType pContractType)
    {
        return toAjax(pContractTypeService.insertPContractType(pContractType));
    }

    /**
     * 修改合同类型
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:edit')")
    @Log(title = "合同类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PContractType pContractType)
    {
        return toAjax(pContractTypeService.updatePContractType(pContractType));
    }

    /**
     * 删除合同类型
     */
    @PreAuthorize("@ss.hasPermi('contract:contractType:remove')")
    @Log(title = "合同类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ctypeIds}")
    public AjaxResult remove(@PathVariable Long[] ctypeIds)
    {
        return toAjax(pContractTypeService.deletePContractTypeByCtypeIds(ctypeIds));
    }
}
